<?php

require("html_mime_mail_2.5/htmlMimeMail.php");

class Mailer
{
	protected $id_negozio;
	function Mailer($id_negozio)
	{
		$this->id_negozio = $id_negozio;
	}
	
	function sendShopMail($tipo = "registrazione", $obj=0)
	{
		// CARICO TEMPLATE
		ob_start();
		$file_tpl = $_SERVER[HTTP_HOST]."/template/mail_html_$tipo.php";
		if(!file_exists($file_tpl)) $file_tpl = "_default/template/mail_html_$tipo.php";
		include($file_tpl);
		$template_html = ob_get_contents();
		ob_end_clean();
		ob_start();
		$file_tpl = $_SERVER[HTTP_HOST]."/template/mail_text_$tipo.php";
		if(!file_exists($file_tpl)) $file_tpl = "_default/template/mail_text_$tipo.php";
		include($file_tpl);
		$template_testo = ob_get_contents();
		ob_end_clean();
		$mail = new htmlMimeMail();
		$mail->setHeader('X-Mailer', 'mokashop.it mailing');
			
		if($tipo== "registrazione" && is_array($obj))
		{
			$nome_sito = $_SESSION[configurazione][nome_negozio];
			$email_ordini = $_SESSION[configurazione][email_ordini];
			$email_info = $_SESSION[configurazione][email_info];
			$email_to = $obj[email];
			
			$oggetto = _s("Benvenuto %s %s",$obj[nome], $obj[cognome]);
			
			// RECUPERA EMAIL DEST DA id_obj	
			//$mail->setReturnPath($email_sito);
			$mail->setFrom($nome_sito." <$email_info>");					
			$mail->setHeader("Reply-To",$email_info);	
			$mail->setHtml($template_html, $template_testo);			
			$mail->setSubject($oggetto);			
			$mail->send(array($email_to));
			
		}
		if($tipo == "conferma_ordine" && is_object($obj))
		{

			$nome_sito = $_SESSION[configurazione][nome_negozio];
			$email_ordini = $_SESSION[configurazione][email_ordini];
			$email_info = $_SESSION[configurazione][email_info];
			$email_to = $obj->pagam_email;
			
			$oggetto = _s("Conferma ordine %s",$nome_sito);
			
			// RECUPERA EMAIL DEST DA id_obj	
			//$mail->setReturnPath($email_sito);
			$mail->setFrom($nome_sito." <$email_info>");	
			$mail->setHtmlCharset("UTF-8");	
			$mail->setTextCharset("UTF-8");			
			$mail->setHeader("Reply-To",$email_info);	
			$mail->setHtml($template_html, $template_testo);			
			$mail->setSubject($oggetto);			
			$mail->send(array($email_to));
			$mail->setSubject(_s("Conferma ordine n.%s di %s %s",$obj->id, $obj->pagam_nome, $obj->pagam_cognome));
			$mail->send(array($email_info));
			
		}
		
			
		


	}
}


?>